package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domian.DTO.QuestionFormDTO;
import com.tianji.learning.domian.query.QuestionPageQuery;
import com.tianji.learning.domian.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-03-21
 */
@Slf4j
@RestController
@RequestMapping("/questions")
@Api(tags = "互动问题相关接口")
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final IInteractionQuestionService questionService;

    @PostMapping
    @ApiOperation("新增互动问题")
    public void createQuestion(@Valid @RequestBody QuestionFormDTO questionFormDTO) {
        log.info("创建互动问题");
        questionService.createQuestion(questionFormDTO);
    }

    /**
     * 根据id删除当前用户问题
     */
    @ApiOperation("根据id删除当前用户问题")
    @DeleteMapping("/{id}")
    public void deleteQuestion(
            @ApiParam(value = "问题id", example = "1") @PathVariable("id") Long id) {
        questionService.deleteById(id);
    }

    /**
     * 修改提问
     */
    @ApiOperation("修改提问")
    @PutMapping("/{id}")
    public void updateQuestion(
            @ApiParam("要修改的问题的id") @PathVariable("id") Long id,
            @RequestBody QuestionFormDTO questionDTO) {
        questionService.updateQuestion(id, questionDTO);
    }

    @GetMapping("page")
    @ApiOperation("分页查询互动问题")
    public PageDTO<QuestionVO> queryQuestionPage(QuestionPageQuery pageQuery) {
        return questionService.queryQuestionPage(pageQuery);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询互动问题")
    public QuestionVO queryQuestionById(@PathVariable("id") Long id) {
        log.info("根据id查询互动问题");
        return questionService.queryQuestionById(id);
    }
}
